﻿namespace RockPaperScissors.Web.Utility.Tests
{
    using GravityWorks.RockPaperScissors.Toolkit;
    using NUnit.Framework;
    using RockPaperScissors.Core;
    
    [TestFixture]
    public class RulesTest
    {
        private const int ROUND_ONE = 1;
        private const int ROUND_TWO = 2;

        [Test]
        public void Should_Return_Lose_When_Team1_Throws_Invalid_Dynamite()
        {
            RuleSet ruleSet = new RuleSet().CreateRuleSet(true, true, true, false, 0);
            MoveType firstTeamMove = MoveType.Dynamite;
            MoveType secondTeamMove = MoveType.Paper;
            IPlayer firstTeam = new MockPlayer();
            IPlayer secondTeam = new MockPlayer();
            string firstTeamName = "team1";
            string secondTeamName = "team2";
            MatchResult result = CompeteHelper.CalculateWinner(firstTeamName, firstTeamMove, secondTeamName, secondTeamMove, ruleSet, new GameLog());

            Assert.IsTrue(result.WinnerTeamName == "team2");
        }

        [Test]
        public void Should_Not_Be_Able_To_Change_Rules()
        {
            RuleSet ruleSet = new RuleSet().CreateRuleSet(true, true, true, true, 3);
            GameLog gameLog = new GameLog().CreateGameLogWithNoDynamiteLeftForTeam("team1", 3);
            IPlayer firstTeam = new Mocks.MockCheatRulesPlayer();
            IPlayer secondTeam = new MockPlayer();
            MoveType firstTeamMove = CompeteHelper.GetShot(firstTeam, gameLog, ruleSet, 1);
            MoveType secondTeamMove = MoveType.Paper;

            string firstTeamName = "team1";
            string secondTeamName = "team2";
            MatchResult result = CompeteHelper.CalculateWinner(firstTeamName, firstTeamMove, secondTeamName, secondTeamMove, ruleSet, gameLog);

            Assert.IsTrue(result.WinnerTeamName == "team2");
        }

        [Test]
        public void Stack_Over_Flow()
        {
            RuleSet ruleSet = new RuleSet().CreateRuleSet(true, true, true, true, 3);
            GameLog gameLog = new GameLog().CreateGameLogWithNoDynamiteLeftForTeam("team1", 3);
            IPlayer firstTeam = new Mocks.MockStackOverflowPlayer();
            IPlayer secondTeam = new MockPlayer();
            MoveType firstTeamMove = CompeteHelper.GetShot(firstTeam, gameLog, ruleSet, 1);
            MoveType secondTeamMove = MoveType.Paper;

            string firstTeamName = "team1";
            string secondTeamName = "team2";
            MatchResult result = CompeteHelper.CalculateWinner(firstTeamName, firstTeamMove, secondTeamName, secondTeamMove, ruleSet, gameLog);

            Assert.IsTrue(result.WinnerTeamName == "team2");
        }
    }
}
